<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<script>
			let arr = [{
				id: 7,
				name: '北京',
				childrens: [{
					id: 8,
					name: '朝阳',
					childrens: [{
						id: 9,
						name: '国贸',
					}, ],
				}],
			}, {
				id: 1,
				name: '四川',
				childrens: [{
					id: 2,
					name: '成都',
					childrens: [{
							id: 3,
							name: '青羊',
							childrens: [{
								id: 10,
								name: '优品道',
							}, ],
						},
						{
							id: 4,
							name: '高新',
							childrens: [{
								id: 5,
								name: '中和',
							}, ]
						},
					]
				}, {
					id: 6,
					name: '自贡',
				}]
			}]
			let obj = {}; // 找到的对象
			let lock = false; // 判断是否找到
			function test(arr, targetName) {
				console.log("arr=>", arr);
				arr.forEach(item => {
					if (item.name === targetName) {
						obj = item;
						lock = true;
						return;
					}
					if (!!item.childrens && item.childrens.length > 0 && !lock) { // 有数组 数组长度>0 并且没有找到
						test(item.childrens, targetName);
					}
				})
			}

			test(arr, "中和");
			console.log(obj, lock)
		</script>
	</body>
</html>
